package com.wx.mythread.stopthread;

/**
 * run方法中沒有sleep或者wait方法停止線程
 */
public class RightWayStopThreadWithOutSleep implements Runnable {


    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new RightWayStopThreadWithOutSleep());
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }

    @Override
    public void run() {
        int num=0;
        while (num < Integer.MAX_VALUE / 2 && !Thread.currentThread().isInterrupted()){
            if (num % 10000 == 0){
                System.out.println(num + "为10000的倍数");
            }
            num++;
        }
        System.out.println("运行结束");
    }
}
